<!-- 跟单-发起策略列表-->
<template>
  <div class="all">

    <!-- 类型 -->
    <SubMenuOval class="menu" :menus="menus" :menu="menu" :max="false" @menuClick="menuClick"></SubMenuOval>
    
    <list class="list" :loadmoreoffset="50" @loadmore="httpStrategysLoading">
      
      <!--刷新-->
      <refresh class="refresh" @refresh="httpStrategys(menu)" :display="isRefresh ? 'show' : 'hide'">
        <loading-indicator class="load text1"></loading-indicator>
      </refresh>

      <!--内容-->
      <cell v-for="(item, index) in strategys" v-bind:key="index">
        
        <div class="cell bg2" v-if="item.followName" @click="strategyClick(item)">
          
          <div class="cell-content">
            
            <div class="cell-info bg2">
              <LImage class="texture2" :src="Config.img('texture2.png')"></LImage>

              <div class="column">
                <div class="row acenter">
                  <text class="font32 text1">{{T(item.followName)}}</text>
                  <div class="cell-exch bk1">
                    <text class="font20 text1">{{item.exchangeNames[0]}}</text>
                  </div>
                </div>
                <div class="height20"></div>
                <div class="row">
                  <div class="cell-tag bk1" v-for="(item, index) in item.mark" v-bind:key="index">
                    <text class="font20 main-t1">{{item}}</text>
                  </div>
                </div>
              </div>

              <div class="column aend">
                <text :class="['font32',Config.upDownFont(item.realYearIncome)]">{{math.addJia(item.realYearIncome)+'%'}}</text>
                <div class="height20"></div>
                <text class="font24 text3">{{T('年化收益率')}}</text>
              </div>
            </div>

            <div class="cell-total bg3" @click="userClick(item.userId)">
              <div class="user">
                <LImage class="user-image bg3" :src="item.avatar ? item.avatar : (Config.img('view_image_portrait_normal.png'))"></LImage>
                <text class="font20 text3">{{item.nickName}}</text>
              </div>
              <div class="all"></div>
              <text class="font20 text3">{{item.startTimeStr}}</text>
            </div>
            
            <div :class="['cellof-type', item.isContract ? 'cellof-type-hong' : '']">
              <text :class="['font22', item.isContract ? 'udRed-t1' : 'main-t1']">{{item.isContract ? T('合约') : T('币币')}}</text>
            </div>
          </div>
        </div>

        <div class="tipe" v-else>
          <text class="tipe-text font24 text3">{{T('跟单数据实时更新，历史表现不能代表未来收益；')}}</text>
          <text class="tipe-text font24 text3">{{T('年化收益率较低的数据将不会被展示在列表中；')}}</text>
          <text class="tipe-text font24 text3">{{T('市场有风险，投资需谨慎。')}}</text>
        </div>
      </cell>
    </list>
  </div>
</template>

<script>

//组件
import SubMenuOval from '@/public/view/SubMenuOval.vue'

//功能
import Config from "@/_js/config";
import navigator from "@/_js/navigator";
import modal from "@/_js/modal";
import math from "@/_js/math";
import jtime from "@/_js/time";

import weexHttp from "@/_js/https"; ;
const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;

export default {

  components: {
    SubMenuOval,
  },


  data() {
    return {
      Config:Config,
      T:T,
      math:math,

      menu:0,
      menus:[T('全部'), T('币币'), T('合约')],
      menud:['', 'spot', 'contract_usdt'],

      strategys:[], //策略列表
      
      pageNo:0, //页码
      pageMax:false, //turn最大页面
      
      isRefresh:false, //显示刷新
      isLoadinging:false, //显示加载

      isContract:false, //turn合约
    };
  },

  mounted() {

    Config.init(()=>{
      this.httpStrategys(this.menu);
    },[Config.OPT_UP_DOWN]);
  },
  
  methods: {
    
    /*************************************************通信触发*/
    //完全显示
    viewappear() {
    },

    /********************************** HTTP*/
    //策略列表-刷新
    httpStrategys(menu) {
      if (this.isRefresh || this.isLoadinging) return;
      this.isRefresh = true;

      var param = {'pageNo':1, 
                   'isContract':this.menud[menu]};
      weexHttp.post("follow/queryFollowStrategyList",param, false,(data) => {
          this.isRefresh = false;
          this.menu = menu;

          if (data.status == 200) {
            data = data.data;
            this.opData(data);

            this.strategys = data;
            this.pageNo = 1;
            this.pageMax = data.length < 20;
            if(data.length < 20) this.strategys.push({});
          } else {
            modal.toast(data.msg);
          }
        }
      );
    },

    //策略列表-加载
    httpStrategysLoading() {
      if (this.pageMax || this.isRefresh || this.isLoadinging) return;
      this.isLoadinging = true;

      var param = {'pageNo': this.pageNo+1, 
                   'isContract':this.menud[this.menu]};
      weexHttp.post("follow/queryFollowStrategyList",param,false,(data) => {
        this.isLoadinging = false;

        if (data.status == 200) {
          data = data.data;
          this.opData(data);

          this.strategys.push(...data);
          this.pageNo++;
          this.pageMax = data.length < 20;
          if(data.length < 20) this.strategys.push({});
        } else {
          modal.toast(data.msg);
        }
      });
    },

    /*************************************************其他*/
    //处理数据
    opData(data){
      for (let index = 0; index < data.length; index++) {
        var datas = data[index];
        datas.exchangeNames = datas.exchangeNames ? datas.exchangeNames : [];
        datas.mark = datas.mark ? datas.mark : [];
        datas.isContract = (datas.isContract == 'contract' || datas.isContract == 'contract_usdt');
        datas.startTimeStr =  jtime.getTime(datas.startTime)
      }
    },

    /********************************** 点击触发*/
    menuClick(menu) {
      this.httpStrategys(menu);
    },

    //策略点击
    strategyClick(item){
      if (!Config.forceLogin()) return;
      
      var param = {'executeId':item.executeId};
      navigator.open(item.followName, "follw/UFollwStrategyInfo",param);
    },
  },
};
</script>


<style src="@/_css/style.css"></style>
<style scoped>

/********************************************************************* 列表*/
.list {
  margin-top: 20px;
  flex: 1;
}
.cell {
  position:relative;
  flex-direction: column;
  align-items: center;
  width: 710px;
  margin-left:20px;
  margin-top: 20px;
}
.cell-content {
  flex-direction: column;
  width: 710px;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}
.cell-info {
  flex-direction: row;
  justify-content: space-between;
  width: 710px;
  height:200px;
  padding: 50px;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}
.cell-exch {
  flex-direction: row;
  align-items: center;
  height: 33px;

  border-radius: 20px;
  border-width: 2px;

  padding-left: 15px;
  padding-right: 15px;

  margin-left: 12px;
}
.cell-tag {
  height: 34px;
  justify-content: center;
  align-items: center;
  border-top-left-radius: 14px;
  border-top-right-radius: 14px;
  border-bottom-right-radius: 14px;
  border-width: 2px;
  padding-left: 12px;
  padding-right: 12px;
  margin-right: 12px;
}
.cell-total {
  flex-direction: row;
  align-items: center;
  width: 710px;
  height: 64px;
  padding-left: 48px;
  padding-right: 48px;

  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}
.user{
  flex-direction: row;
  align-items: center;
}
.user-image{
  width:40px;
  height:40px;
  border-radius: 20px;
  margin-right:10px;
}

/*********************** 类型标签*/
.cellof-type{
  position: absolute;
  flex-direction: row;
  align-items: center;
  height: 32px;
  padding-left: 10px;
  padding-right: 10px;
  border-top-right-radius: 8px;
  border-bottom-left-radius: 8px;

  background-color: rgba(22, 119, 254, 0.1);

  top: 0;
  right: 0;
}
.cellof-type-hong{
  background-color: rgba(252, 97, 128, 0.1);
}

/*********************** 弹出菜单*/
.menu {
  margin-left: 20px;
  margin-right: 20px;
  margin-top: 40px;
}

/*********************** 刷新*/
.refresh {
  width: 750;
  flex-direction: row;
  justify-content: center;
}
.load {
  margin-top: 16px;
  height: 40px;
  width: 40px;
}

/*********************** 提示*/
.tipe {
  margin-left: 60px;
  margin-right: 60px;
  margin-top: 40px;
  margin-bottom: 40px;
}
.tipe-text {
  line-height: 30px;
}

/*********************** 宽高*/
.height20{
  height: 20px;
}
</style>